package com.cskaoyan.factory;

import com.cskaoyan.bean.Animal;
import com.cskaoyan.bean.Bull;
import com.cskaoyan.bean.Pig;
import com.cskaoyan.bean.Rabbit;

public class AnimalFactory {

    public Animal create(String name) {
        if ("pig".equals(name)) {
            return new Pig();
        }
        if ("rabbit".equals(name)) {
            return new Rabbit();
        }
        //开闭原则 → 对修改封闭
        if ("bull".equals(name)) {
            return new Bull();
        }
        return null;
    }
}
